package thread;

public class ThreadInterrupt {
    private static boolean isQuit = false;//isQuit不能定义为局部变量 lambda表达式变量捕获-不可改变
    public static void main(String[] args) {
        Thread t = new Thread(()->{
            while (!isQuit){//isQuit=true时跳出循环
                System.out.println("线程开始咯!");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
            System.out.println("线程执行完成咯!");
        });
        t.start();
        try {
            Thread.sleep(3000);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }

        isQuit = true;
        System.out.println("让t线程结束");
    }
}
